package com.usian.controller;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.usian.PageResult;
import com.usian.pojo.TbItem;
import com.usian.pojo.TbItemDesc;
import com.usian.service.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Api("商品管理接口")
public class ItemController {

    @Autowired
    private ItemService itemService;


    @PostMapping("selectItemInfo")
    @ApiOperation(value = "查询商品信息",notes = "根据商品id查询商品信息")
    @ApiImplicitParam(name = "itemId",type ="Long",value = "商品id")
    public TbItem selectItemInfo(@RequestParam Long itemId){
        return itemService.findItemById(itemId);
    }

    /**
     * 查询商品列表
     *
     * @param page
     * @param rows
     * @return
     */

    @GetMapping("selectTbItemAllByPage")
    @ApiOperation(value = "查询商品列表",notes = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",type ="Integer",value = "页码"),
            @ApiImplicitParam(name = "rows",type ="Integer",value = "条数")
    }
    )
    public PageResult selectTbItemAllByPagePage(@RequestParam Integer page,@RequestParam Integer rows){
        return itemService.selectTbItemAllByPage(page,rows);
    }

    /**
     * 商品添加
     *
     * @param tbItem
     * @param desc
     * @param itemParams
     * @return
     */
    @RequestMapping("insertTbItem")
    public  Integer  insertTbitem(@RequestBody TbItem tbItem,@RequestParam String desc,@RequestParam String itemParams){
         return itemService.insertTbitem(tbItem,desc,itemParams);
    }

    /**
     * 商品信息回显
     *
     * @param ItemId
     * @return
     */
    @RequestMapping("preUpdateItem")
    public Map<String,Object> preUpdateItem(@RequestParam  Long ItemId){
        return itemService.preUpdateItem(ItemId);
    }

    /**
     * 商品修改
     *
     * @param tbItem
     * @param desc
     * @param itemParams
     * @return
     */
    @RequestMapping("updateTbItem")
    public  Integer  updateTbItem(@RequestBody TbItem tbItem,@RequestParam String desc,@RequestParam String itemParams){
        return itemService.updateTbItem(tbItem,desc,itemParams);
    }


    /**
     * 删除商品
     * @param itemId
     * @return
     */
    @RequestMapping("deleteItemById")
    public Integer deleteItemById(@RequestParam Long itemId){
        return itemService.deleteItemById(itemId);
    }


    /**
     * 根据itemid 查询 商品详情
     *
     * @param itemId
     * @return
     */
    @RequestMapping("selectItemDescByItemId")
    public TbItemDesc selectItemDescByItemId(@RequestParam Long itemId){
        return itemService.selectItemDescByItemId(itemId);
    }
}
